Introduction
The AHT20 is a high-precision but low-cost temperature and humidity sensor, which is equipped with an improved MEMS semiconductor capacitive humidity sensor element. It features standard I2C interface and a wide voltage supply of 2V - 5V. And with simple peripheral circuit, it performs stably even in harsh environments in the measuring range of -40 - +85℃. This sensor can be widely used for measuring the environmental temperature and humidity of home electronic equipment, the temperature and humidity of automobiles and so on.
Features
- Digital output, I2C interface
- Excellent long-term stability
- Quick response and strong anti-interference ability
Applications
- HVAC
- Dehumidifier
- Testing and Inspection Equipment
- Consumer Appliances
- Automobiles
- Automatic Control
- Data Loggers
- Weather Stations
Pinout
Pin | Function | Description |
---|---|---|
VCC | + | Power Supply: DC 2V~5V |
GND | - | -- |
SCL | I2C Clock Line | -- |
SDA | I2C Data Line | -- |
Specification
Module Parameters
- Operating Voltage: DC2V~5V
- Output Signal: I2C
- I2C Address: 0x38
- Dimension: 30mm×20.5mm/1.18×0.81"
AHT20 Chip Parameters
Relative Humidity
- Resolution: 0.024 %RH
- Accuracy Error: ±2% RH
- Repeatability: ±0.1 %RH
- Hysteresis: ±1 %RH
- Non-linear: ±0.1 %RH
- Response Time: 8S
- Operating Range: 0~100 %RH
- Long-term Drift: <0.5 %RH/yr
Temperature
- Resolution: 0.01℃
- Accuracy Error: ±0.3℃
- Repeatability: ±0.1℃
- Hysteresis: ±0.1℃
- Response Time: minimum 5S, maximum 30S
- Operating Range: -40℃~85℃
- Long-term Drift: <0.04℃/yr
Dimension Diagram
Tutorial
Hardware Requirement
- DFRduino UNO R3 (or similar) x 1
- SEN0527 Fermion: AHT20 Temperature and Humidity Sensor x 1
- M-M/F-M/F-F Jumper wires
Software Requirement
- Arduino IDE
- Download and install the DFRobot_AHT20 Library (About how to install the library?)
Connection Diagram
UNO Board: 3V3 - connect to - AHT20:VCC
UNO Board: GND - connect to - AHT20:GND
UNO Board: SCL - connect to - AHT20:SCL
UNO Board: SDA - connect to - AHT20:SDA
Sample Code
The following code will read the measured values from the AHT20 temperature and humidity sensor and print them through the serial port.
#include "DFRobot_AHT20.h"
DFRobot_AHT20 aht20;
void setup(){
Serial.begin(115200);
uint8_t status;
while((status = aht20.begin()) != 0){
Serial.print("AHT20 sensor initialization failed. error status : ");
Serial.println(status);
delay(1000);
}
}
void loop(){
if(aht20.startMeasurementReady(/* crcEn = */true)){
Serial.print(aht20.getTemperature_C());
Serial.print(" C, ");
// Get temp in Fahrenheit (F)
Serial.print(aht20.getTemperature_F());
Serial.print(" F\t");
Serial.print(aht20.getHumidity_RH());
Serial.println(" %RH");
delay(5000);
}
}
Result
As shown in the figure below, the temperature values in ℃ and ℉, and humidity values are displayed in the serial monitor.
API Function
/**
* @fn DFRobot_AHT20
* @brief DFRobot_AHT20 constructor
* @param wire TwoWire class object reference
* @return NONE
*/
DFRobot_AHT20(TwoWire &wire = Wire);
/**
* @fn begin
* @brief Initialize AHT20 sensor
* @return Init status value
* @retval 0 Init succeeded
* @retval 1 _pWire is NULL, please check if the constructor DFRobot_AHT20 has correctly uploaded a TwoWire class object reference
* @retval 2 Device is not found, please check if the connection is correct
* @retval 3 If the sensor init fails, please check if there is any problem with the sensor, you can call the reset function and re-initialize after restoring the sensor
*/
uint8_t begin();
/**
* @fn reset
* @brief Sensor soft reset, restore the sensor to the initial status.
* @return NONE
*/
void reset();
/**
* @fn startMeasurementReady
* @brief Start measurement and determine if it’s completed.
* @param crcEn Whether to enable check during measurement
* @n false Measure without check (by default)
* @n true Measure with check
* @return Whether the measurement is done
* @retval true If the measurement is completed, call a related function such as get* to obtain the measured data.
* @retval false If the measurement failed, the obtained data is the data of last measurement or the initial value 0 if the related function such as get* is called at this time.
*/
bool startMeasurementReady(bool crcEn = false);
/**
* @fn getTemperature_F
* @brief Get ambient temperature, unit: Fahrenheit (F).
* @return Temperature in F
* @note AHT20 can't directly get the temp in F, the temp in F is calculated according to the algorithm: F = C x 1.8 + 32
* @n Users must call the startMeasurementReady function once to start the measurement before calling this function so as to get the real-time measured data,
* @n otherwise what they obtained is the initial data or the data of last measurement.
*/
float getTemperature_F();
/**
* @fn getTemperature_C
* @brief Get ambient temperature, unit: Celsius (℃).
* @return Temperature in ℃, it's normal data within the range of -40-85℃, otherwise it's wrong data
* @note Users must call the startMeasurementReady function once to start the measurement before calling this function so as to get the real-time measured data,
* @n otherwise what they obtained is the initial data or the data of last measurement.
*/
float getTemperature_C();
/**
* @fn getHumidity_RH
* @brief Get ambient relative humidity, unit: %RH.
* @return Relative humidity, range 0-100
* @note Users must call the startMeasurementReady function once to start the measurement before calling this function so as to get the real-time measured data,
* @n otherwise what they obtained is the initial data or the data of last measurement
*/
float getHumidity_RH();
More Documents
SEN0527-Circuit Diagram SCH.pdf
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.